package com.bing;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.boot.MetadataSources;
import org.hibernate.boot.registry.StandardServiceRegistry;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;

/**
 * hibernate 工具集
 * Created by kaibb on 15-11-1.
 */
public abstract class HUtils {

    private static class Holder {
        public static final SessionFactory mySqlFactory;

        static {

            final StandardServiceRegistry mySqlRegistry = new StandardServiceRegistryBuilder()
                    .configure("mysql_hibernate.cfg.xml").build();
            mySqlFactory = new MetadataSources(mySqlRegistry).buildMetadata().buildSessionFactory();
        }
    }

    public static Session getMySqlSession() {
        return Holder.mySqlFactory.openSession();
    }
}
